﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections.Specialized;

/// <summary>
/// Summary description for OperateSQL
/// </summary>


    public partial class DepartManager : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected void Button1_Click(object sender, EventArgs e)
        {

            OperateSQL osql = new OperateSQL();
            string sqlstring = "select employee.* from employee,dept,project where dept.DeptName ='" +
                DropDownList1.Text.Trim() + "' and employee.DeptID=dept.DeptID and project.projID=employee.projID";
            DataSet three_ds = null;
            if (DropDownList2.SelectedValue.Equals(""))
            {               
                three_ds = osql.GetDataSet(sqlstring);             
            }
            if (DropDownList2.SelectedValue.Equals("1"))
            {
                three_ds = osql.GetBJDataSet(sqlstring);
            }
            if (DropDownList2.SelectedValue.Equals("2"))
            {
                three_ds = osql.GetSHDataSet(sqlstring);
            }
            if (DropDownList2.SelectedValue.Equals("3"))
            {
                three_ds = osql.GetGZDataSet(sqlstring);
            }
            this.GridView1.DataSource = three_ds;
            this.GridView1.DataBind();
        }

        /*
        private OrderedDictionary ExtractRowValues(DataControlFieldCollection Columns, GridViewRow Row)
        {
            OrderedDictionary oFieldValues;
            OrderedDictionary oDictionary;
            DataControlField oColumn;

            oFieldValues = new OrderedDictionary(Columns.Count);
            oDictionary = new OrderedDictionary();

            for (int i = 0; i < Columns.Count; i++)
            {
                oColumn = Columns[i];
                if (oColumn.Visible)
                {
                    oDictionary.Clear();
                    oColumn.ExtractValuesFromCell(oDictionary, (DataControlFieldCell)Row.Cells[i], Row.RowState, true);
                    foreach (DictionaryEntry oEntry in oDictionary)
                    {
                        oFieldValues.Add(oEntry.Key, oEntry.Value);
                    }
                }
            }

            return oFieldValues;
        }
        */

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowIndex != -1)
            {
                e.Row.Attributes.Add("onmouseover", "this.style.background='#E2E2E2'");
                e.Row.Attributes.Add("onmouseout", "this.style.background='#ffffff'");
                //e.Row.Attributes.Add("onclick", "this.style.background='#ffffff'");
                //e.Row.Attributes.Add("onmousedown", "this.style.background='#8EC26F'"); //给行添加单击事件
            }
        }

        /*
        protected void Button2_Click(object sender, EventArgs e)
        {
            GridViewRow oRow;
            System.Collections.Specialized.OrderedDictionary oFieldValues;
            oRow = (GridViewRow)GridView1.Rows[GridView1.SelectedIndex];
            oFieldValues = ExtractRowValues(GridView1.Columns, oRow);

            string url = "DepartChange.aspx?";
            url += "&param1=" + oFieldValues["EmployID"].ToString(); 
            url += "&param2=" + oFieldValues["EmployName"].ToString();
            url += "&param3=" + oFieldValues["DeptID"].ToString();
            url += "&param4=" + oFieldValues["ProjID"].ToString(); 
            Response.Redirect(url);


        }
        */

        protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
        {
            GridView1.SelectedIndex = e.NewSelectedIndex;
            string url = "DepartChange.aspx?";
            url += "&param1=" + this.GridView1.SelectedRow.Cells[1].Text;
            url += "&param2=" + this.GridView1.SelectedRow.Cells[2].Text;
            url += "&param3=" + this.DropDownList1.SelectedValue;
            Response.Redirect(url);
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            string url = "DepartAdd.aspx?";
            url += "&param1=" + this.DropDownList2.SelectedValue;
            url += "&param2=" + this.DropDownList1.SelectedValue;
            Response.Redirect(url);
        }
        protected void Button3_Click(object sender, EventArgs e)
        {
            string url = "DepartModify.aspx?";
            url += "&param1=" + this.DropDownList2.SelectedValue;
            url += "&param2=" + this.DropDownList1.SelectedValue;
            Response.Redirect(url);
        }
}

